﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace BawangMemo.BackendModels
{
    public class WordWrapper
    {
        public CourseWrapper Course { get; private set; }

        public int Id { get; private set; }

        public WordInfo WordInfo { get; set; }

        public string Spell { get; set; }

        #region Construction

        public WordWrapper(CourseWrapper course, int id)
        {
            Course = course;
            Id = id;
            WordInfo = new WordInfo(id);
            Spell = GetWordCard(course, id).Spell;

        }

        public WordWrapper(CourseWrapper course, WordInfo wi)
        {
            Course = course;
            Id = wi.WordId;
            WordInfo = wi;
            Spell = GetWordCard(course, Id).Spell;
        }

        public override string ToString()
        {
            return Spell;
        }

        #endregion

        #region Methods for WordView

        public void SaveWordInfo()
        {
            WordRepository.SaveWordInfo(Course.CourseName, WordInfo);
        }

        public WordCard GetWordCard()
        {
            //return WordRepository.LoadWordCardFromCourse(Course, Id);
            return Course.GetWordCard(Id);
        }

        public static WordCard GetWordCard(CourseWrapper cw, int wordId)
        {
            return cw.GetWordCard(wordId);
        }

        public void UserResponse(int proficiency)
        {
            this.Course.UserResponse(this, proficiency);
        }

        #endregion

        #region Methods for TestView

        public bool IsNewWord()
        {
            return WordInfo.TotalMemCount == 0;
        }

        #endregion

        #region Methods for MemView

        public void AddTag(string tag)
        {
            TagRepository.AddTag(this, tag);
        }

        public void RemoveTag(string tag)
        {
            TagRepository.RemoveTag(this, tag);
        }

        public List<string> ListWordTags()
        {
            return TagRepository.ListWordTags(this);
        }

        #endregion

        public void ChangeScore(int proficiency)
        {
            RecordRepository.LogMemRecord(this, proficiency);
            Helper.UserResponseStatic(this, proficiency, null);
        }
    }
}
